/*
 * @lc app=leetcode.cn id=455 lang=cpp
 *
 * [455] 分发饼干
 */

// @lc code=start
class Solution
{
public:
  int findContentChildren(vector<int>& g, vector<int>& s)
  {
    sort(g.begin(), g.end());
    sort(s.begin(), s.end());
    int ans = 0, idx = 0;
    int m = g.size(), n = s.size();
    for (int i = 0; idx < n && i < m; ++i) {
      while (idx < n) {
        if (s[idx++] >= g[i]) {
          ++ans;
          break;
        }
      }
    }
    return ans;
  }
};
// @lc code=end
